#include "VulkanDescriptorPool.h"
#include "Render/VulkanContext.h"
void CVulkanAutoResetDescriptorPool::ClearPool()
{
    if(!Pool) 
    {
        return;
    }

    CVulkanContext::Get()->GetDevice().destroyDescriptorPool(Pool);
    PoolSize.Clear();
    Pool=nullptr;
}

void CVulkanAutoResetDescriptorPool::CreatePool()
{
    Pool=PoolSize.CreateDescriptorPool(CVulkanContext::Get()->GetDevice());
}

vk::DescriptorSet CVulkanAutoResetDescriptorPool::AllocateDescriptorSets(const SVulkanDescriptorLayout &Layout)
{
    vk::DescriptorSetAllocateInfo AllocInfo=vk::DescriptorSetAllocateInfo()
        .setDescriptorPool(Pool)
        .setDescriptorSetCount(1)
        .setPSetLayouts(&Layout.Layout);
    return CVulkanContext::Get()->GetDevice().allocateDescriptorSets(AllocInfo)[0];
}

void CVulkanAutoResetDescriptorPools::ClearPools()
{
    GenerallPool.ClearPool();
    MeshInstancePool.ClearPool();
    MaterialPool.ClearPool();

    CanvasPool.ClearPool();
}

void CVulkanAutoResetDescriptorPools::CreatePools()
{
    GenerallPool.CreatePool();
    MeshInstancePool.CreatePool();
    MaterialPool.CreatePool();
    
    CanvasPool.CreatePool();
}
